// itemdata swf
#ifndef _GEN_TEXT_SWF_HPP_
#define _GEN_TEXT_SWF_HPP_

#include "itemdata.hpp"

// here everything in pixel unit!!!

class text_swf:public xlider_generator {
		
public:
	
	virtual void create_bullet(SWFSprite* grp){
		int r,g,b;
		if(get_bullet_type()!=""&&get_bullet_type()!="none") {
			double brad=floor(get_bullet_radius());		
			SWFShape *bullet=new SWFShape;
			convert_color(get_bullet_color(),r,g,b);
			SWFFill *fillsty=bullet->addSolidFill(r,g,b);
			bullet->setRightFill(fillsty);
			bullet->drawCircle(brad);
			SWFDisplayItem *da=grp->add(bullet);
			da->move(get_offsetx(),get_offsety()-get_fontsize()/4.0);
			set_width(it->width-get_line_offset());
		}
	}
	
	// returns height of object
	virtual double draw(void* draw_param) {
		SWFSprite* grp=(SWFSprite*) draw_param;
		int r,g,b;
		
		if(it->text.empty()) return 0.0;

		create_bullet(grp);
		arrange_text();

		SWFFont *cfont=new SWFFont(get_fontpath(get_fontname()).c_str());

		for(int i=0;i<lines.size();i++){
			SWFText *ctext=new SWFText;
			ctext->setFont(cfont);
			convert_color(get_fontcolor(),r,g,b);
			ctext->setColor(r,g,b);
			ctext->setHeight(get_fontsize());
			ctext->addString(lines[i].c_str());
			double tlen=ctext->getWidth(lines[i].c_str());
			SWFDisplayItem *db=grp->add(ctext);
			db->move(get_shiftx(tlen),get_shifty(i));
		};

		return get_actual_height();
	}

	virtual void* generate(void* param=NULL){
		SWFSprite *grp=new SWFSprite;
		set_height(draw(grp));
		grp->nextFrame();
		return grp;
	}

};

#endif
